//
//  ZJShopCarViewController.m
//  ZiJinLian
//
//  Created by lzy on 2017/3/10.
//  Copyright © 2017年 lzy. All rights reserved.
//

#import "ZJShopCarViewController.h"
#import "ZJLoginViewController.h"
#import "ZJBaseNavControllerViewController.h"
#import "ShoppingCarTableViewCell.h"
#import "shoppingCarModel.h"
#import "SDAutoLayout.h"
#import "MessageViewController.h"
#import "SubmitOrderViewController.h"
#import "YXCustomAlertView.h"

@interface ZJShopCarViewController ()<UITableViewDelegate,UITableViewDataSource,YXCustomAlertViewDelegate>
@property (nonatomic, strong) UIButton * seleteBtn;
@property (nonatomic, strong) UILabel  * allpriceLabel;
@property (nonatomic, strong) UILabel  * numberLabel;
@property (nonatomic, strong) UIButton * chooseAllBtn;
@property (nonatomic, strong) NSString * singlenum;
@property (nonatomic ,strong) NSString * totalprice;
@property (nonatomic, strong) UIImage  * itemImage;
@property (nonatomic, strong) UITableView * tableView;
@property (nonatomic, strong) UIView   * tempsView;
@property (nonatomic, strong) shoppingCarModel * model;
@property (nonatomic, strong) NSMutableArray   * shopDataArr;
@property (nonatomic, strong) NSMutableArray   * chooseArray;
@property (nonatomic, strong) ShoppingCarTableViewCell  * cell;
@property (nonatomic, assign) BOOL isDelete;
@property (nonatomic, assign) BOOL isSelect;
@property (nonatomic, assign) int  numLabel;




@end

@implementation ZJShopCarViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    self.chooseArray = [NSMutableArray array];
    self.title = MyString(@"购物车");
    [self createdUI];
    [self viewIsDetemp];
    //[self.view addSubview:self.tableView];
    self.itemImage= [UIImage imageNamed:@"icon_message_nor"];
    self.itemImage = [self.itemImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIBarButtonItem *rightBarButtonItem=[[UIBarButtonItem alloc]initWithImage:self.itemImage style:UIBarButtonItemStylePlain target:self action:@selector(rightClick)];
    self.navigationItem.rightBarButtonItem =rightBarButtonItem;
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(InfoNotificationAction) name:@"unReadInfo" object:nil];
}
-(void)InfoNotificationAction{
    self.itemImage= [UIImage imageNamed:@"icon_message_reminder"];
    self.itemImage = [self.itemImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
    UIBarButtonItem *rightBarButtonItem=[[UIBarButtonItem alloc]initWithImage:self.itemImage style:UIBarButtonItemStylePlain target:self action:@selector(rightClick)];
    self.navigationItem.rightBarButtonItem =rightBarButtonItem;
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    [self setupUnreadMessageCount];
    self.chooseAllBtn.selected = NO;
    [self.chooseArray removeAllObjects];
    [self calculateThePrice];
    //[self loadListData];
    if ([ZJUserDefaultsTools isLogin]) {
        self.tempView.hidden=YES;
        [self loadShopList];
    }else{
        self.tempView.hidden=NO;
    }
}

#pragma mark --------- 清空购物车
- (void)rightClick
{
    if ([ZJUserDefaultsTools isLogin]) {
        EaseConversationListViewController *chatController = [[EaseConversationListViewController alloc]init];
        chatController.title=MyString(@"消息");
        [self.navigationController pushViewController:chatController animated:YES];
    }else{
        ZJLoginViewController *controller = [[ZJLoginViewController alloc] init];
        ZJBaseNavControllerViewController* nav=[[ZJBaseNavControllerViewController alloc]initWithRootViewController:controller];
        controller.modality=NO;
        [self presentViewController:nav animated:YES completion:nil];
    }

}

- (void)loadListData
{
    
}
-(UITableView *)tableView{
    if (!_tableView) {
       
    }
    return _tableView;
}
- (void)createdUI
{
    
    _tableView= [[UITableView alloc] initWithFrame:CGRectMake(0, 0, MainW, MainH-64-50-49) style:UITableViewStyleGrouped];
    _tableView.delegate = self;
    _tableView.dataSource = self;
    _tableView.backgroundColor=Gray_Color;
    _tableView.separatorColor=SeparatorColor;
    _tableView.showsVerticalScrollIndicator=NO;
    _tableView.separatorStyle=0;
    [self.view addSubview:_tableView];
    [_tableView registerNib:[UINib nibWithNibName:@"ShoppingCarTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"ShoppingCarCell"];
    //  底部view
    UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, MainH-163, MainW, 50)];
    view.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:view];
    UIButton * btn = [[UIButton alloc] initWithFrame:CGRectMake(3*MainW/4, 0, MainW/4, 50)];
    self.seleteBtn = btn;
    btn.backgroundColor = HJ_Color(204, 8, 20);
    [btn setTitle:[NSString stringWithFormat:@"%@(0)",MyString(@"结算")] forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(toPayClick) forControlEvents:UIControlEventTouchUpInside];
    btn.titleLabel.font =FontAndStyle14;
    [view addSubview:btn];
    UIButton * chooseBtn = [[UIButton alloc] initWithFrame:CGRectMake(15, 15, 20, 20)];
    self.chooseAllBtn = chooseBtn;
    [chooseBtn setBackgroundImage:[UIImage imageNamed:@"icon_rb_nor"] forState:UIControlStateNormal];
    [chooseBtn setBackgroundImage:[UIImage imageNamed:@"icon_rb_pre"] forState:UIControlStateSelected];
    [chooseBtn addTarget:self action:@selector(chooseBtnClick: ) forControlEvents:UIControlEventTouchUpInside];
    UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(45, 15, 30, 20)];
    label.text = MyString(@"全选");
    label.textColor=TextColor6;
    label.font = FontAndStyle14;
    [view addSubview:label];
    [view addSubview:chooseBtn];
    CGSize size=[label.text sizeWithAttributes:@{NSFontAttributeName:label.font }];
    label.frame=CGRectMake(40, 15, size.width, 20);
    
    
    UILabel * allpriceLabel = [[UILabel alloc] initWithFrame:CGRectMake(label.frame.size.width+label.frame.origin.y, 15, MainW*3/4-label.frame.size.width-label.frame.origin.y-10, 20)];
    allpriceLabel.textAlignment = NSTextAlignmentRight;
    allpriceLabel.text = [NSString stringWithFormat:@"%@：¥%@",MyString(@"合计"),@"0.00"];
    allpriceLabel.font = FontAndStyle14;
    allpriceLabel.textColor = TextColor6;
    allpriceLabel.attributedText=[self messageAction:allpriceLabel changeString:[NSString stringWithFormat:@"¥%@",@"0.00"] andAllColor:TextColor6 andMarkColor:Red_Color andMarkFondSize:14];
    self.allpriceLabel = allpriceLabel;
    [view addSubview:allpriceLabel];
    
    
    
}
-(void)refreshClick{
    
}
#pragma mark -------- 全选按钮
- (void)chooseBtnClick:(UIButton *)btn
{
    btn.selected = !btn.selected ;
    [self.chooseArray removeAllObjects];
    if (self.chooseArray.count<self.shopDataArr.count) {
        for (shoppingCarModel * model in self.shopDataArr) {
            model.stated = btn.selected;
            if (btn.selected) {
                [self.chooseArray addObject:model];
            }else{
                [self.chooseArray removeAllObjects];
            }
            
        }
    }
    [self calculateThePrice];
    
    
    [self.tableView reloadData];
}

#pragma mark -------- tableviewdelegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return  self.shopDataArr.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 100;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 10;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.01;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    self.model = self.shopDataArr[indexPath.section];
    
    ShoppingCarTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"ShoppingCarCell"];
    
    cell.numLabel.text=self.model.quantity;
    self.numberLabel=cell.numLabel;
//    NSString*string =[NSString stringWithFormat:@"%@",self.model.name];
//    NSArray *array = [string componentsSeparatedByString:@" "];
    cell.titleLabel.text=self.model.spuName;
    cell.shopStatus.text=self.model.saleName;
    [cell.headImgView sd_setImageWithURL:[NSURL URLWithString:self.model.imageUrl] placeholderImage:[UIImage imageNamed:@"placeholderImage"]];
    cell.moneyLabel.text=[NSString stringWithFormat:@"¥ %@",self.model.price];
    cell.chooseBtn.tag=indexPath.section;
    [cell.chooseBtn addTarget:self action:@selector(chooseOnlyOneBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    //减数量
    cell.nextShopBtn.tag=indexPath.section;
    [cell.nextShopBtn addTarget:self action:@selector(ReduceBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    //加数量
    cell.collectBtn.tag=indexPath.section;
    [cell.collectBtn addTarget:self action:@selector(AddBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    cell.shopNumBtn.tag=indexPath.section;
    [cell.shopNumBtn addTarget:self action:@selector(shopNumClick:) forControlEvents:UIControlEventTouchUpInside];
    //删除
    [cell.seleteBtn addTarget:self action:@selector(seleteBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    cell.seleteBtn.tag = indexPath.section;
    if (self.model.stated) {
        cell.chooseBtn.selected=YES;
    }else{
        cell.chooseBtn.selected=NO;
    }
    [cell.chooseBtn setBackgroundImage:[UIImage imageNamed:@"icon_rb_nor"] forState:UIControlStateNormal];
    [cell.chooseBtn setBackgroundImage:[UIImage imageNamed:@"icon_rb_pre"] forState:UIControlStateSelected];
    return cell;
}
#pragma mark ---------- 点击cell
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
//    self.model = self.shopDataArr[indexPath.section];
//    ShopH5ViewController*vc=[[ShopH5ViewController alloc]init];
//    vc.goods_id=self.model.goods_id;
//    vc.goodStatus=self.model.status;
   // [self.navigationController pushViewController:vc animated:YES];
    
    
}
#pragma mark ---------- 减
-(void)ReduceBtnClick:(UIButton *)sender{
    ShoppingCarTableViewCell*cell=(ShoppingCarTableViewCell *)[[sender superview] superview];
    self.model=self.shopDataArr[sender.tag];
    self.numLabel=[cell.numLabel.text intValue];
    if (self.numLabel>1) {
        self.numLabel-=1;
    }else{
        [self showToast:@"再减就要没有了!"];
        return;
    }
    
    [self changShopNumber:self.model.skuId Number:self.numLabel Click:cell Modle:self.model];
    //[self.tableView reloadData];
}
#pragma mark ---------- 加
-(void)AddBtnClick:(UIButton *)sender{
    ShoppingCarTableViewCell*cell=(ShoppingCarTableViewCell *)[[sender superview] superview];
    self.model=self.shopDataArr[sender.tag];
    self.numLabel=[cell.numLabel.text intValue];
    self.numLabel+=1;
    [self changShopNumber:self.model.skuId Number:self.numLabel Click:cell Modle:self.model];
    //[self.tableView reloadData];
}
#pragma mark ---------- 删除
- (void)seleteBtnClick:(UIButton *)btn
{
    self.model = self.shopDataArr[btn.tag];
    LXAlertView *alert = [[LXAlertView alloc] initWithTitle:nil message:MyString(@"确定删除") cancelBtnTitle:MyString(@"取消") otherBtnTitle:MyString(@"确定") clickIndexBlock:^(NSInteger clickIndex) {
        if (clickIndex==0) {
            NSLog(@"尼玛炸了");
        }else{
            NSMutableDictionary*dic=[[NSMutableDictionary alloc]init];
            dic[@"userId"]=[ZJUserDefaultsTools getCurrentUserID];
            dic[@"skuId"]=self.model.skuId;
            [self doHttpRequestWithApi:API_REMOVESHOPCAR_LIST method:GET dic:dic successBlock:^(NSDictionary *dic) {
                [self.shopDataArr removeObjectAtIndex:btn.tag];
                [self.chooseArray removeObject:self.model];
                [self.tableView reloadData];
                //[self showToast:dic[@"msg"]];
                //[self loadShopList];
                [self calculateThePrice];
                if (self.shopDataArr.count==0) {
                    self.tempView.hidden=NO;
                    if (self.chooseArray.count==0) {
                        self.chooseAllBtn.selected=NO;
                    }
                }
//                dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//                    //[self dismissDialog];
//                    
//                });
                NSLog(@"%@",dic[@"msg"]);
            }];
 
        }
        
    }];
        alert.tag=100;
    [alert showLXAlertView];
}
#pragma mark ----------- 收藏

#pragma mark --------- 选择了一个shop
- (void)chooseOnlyOneBtnClick:(UIButton *)btn
{
    btn.selected =!btn.selected;
    
    if (btn.selected) {
        self.model = self.shopDataArr[btn.tag];
        self.model.stated = btn.selected;
        [self.chooseArray addObject:self.model];
    }else{
        self.chooseAllBtn.selected = NO;
        self.model = self.shopDataArr[btn.tag];
        self.model.stated = btn.selected;
        [self.chooseArray removeObject:self.model];
        
    }
    if (self.chooseArray.count==self.shopDataArr.count) {
        self.chooseAllBtn.selected=YES;
    }
   [self calculateThePrice];
}

#pragma mark ---------- 结算
- (void)toPayClick
{
    if (self.chooseArray.count==0) {
        [MBProgressHUD showError:MyString(@"选择一个")];
        return;
    }
    NSMutableArray *arry=[NSMutableArray array];
    for (shoppingCarModel*model in self.chooseArray) {
        NSString*skuId=model.skuId;
        [arry addObject:skuId];
    }
    NSMutableDictionary*dic=[[NSMutableDictionary alloc]init];
    dic[@"userId"]=[ZJUserDefaultsTools getCurrentUserID];
    dic[@"skuIds"]=[arry mj_JSONString];
    [self doHttpRequestWithApi:API_ShopOrderSettle_LIST method:POST dic:dic successBlock:^(NSDictionary *dic) {
        SubmitOrderViewController * VC = [[SubmitOrderViewController alloc] init];
        VC.orderDic=dic[@"data"];
        VC.title=MyString(@"确认订单");
        VC.skuIdsArray=arry;
        VC.styple=ShopCart;
        [self.navigationController pushViewController:VC animated:YES];

        NSLog(@"  商品的  数组id:%@",dic);
    }];
    
    //    VC.title=@"确认订单";
//    VC.singlenum=self.singlenum;
//    VC.totalprice=self.totalprice;
//    VC.shopArray=self.chooseArray;
//    
    
}

#pragma mark ------------ 结算价格
- (void)calculateThePrice
{
    CGFloat allmoney = 0.00;
    CGFloat lastmoney = 0.00;
    
    for (shoppingCarModel * model in self.chooseArray) {
        CGFloat money = [model.price floatValue] * [model.quantity floatValue]  ;
        allmoney = money + lastmoney;
        lastmoney = allmoney;
    };
           _allpriceLabel.text = [NSString stringWithFormat:@"%@：¥%.1f",MyString(@"合计"),lastmoney];
            _allpriceLabel.attributedText=[self messageAction:_allpriceLabel changeString:[NSString stringWithFormat:@"¥%.1f",lastmoney] andAllColor:TextColor6 andMarkColor:Red_Color andMarkFondSize:18];
            [self.seleteBtn setTitle:[NSString stringWithFormat:@"%@（%ld）",MyString(@"结算"),self.chooseArray.count] forState:UIControlStateNormal];
}


-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    
    [alertView dismissWithClickedButtonIndex:buttonIndex animated:YES];
    switch (alertView.tag) {
        case 100:{
            if (buttonIndex==1) {
                NSLog(@"删除成功");
            }

        }
            break;
        case 200:{
            if (buttonIndex==0) {
                ZJLoginViewController *controller = [[ZJLoginViewController alloc] init];
                ZJBaseNavControllerViewController* nav=[[ZJBaseNavControllerViewController alloc]initWithRootViewController:controller];
                controller.modality=NO;
                [self presentViewController:nav animated:YES completion:nil];
            }

        }
            break;
            
        default:
            break;
    }
    
}
//无数据
-(void)viewIsDetemp{
    self.tempView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, MainW, MainH-64)];
    self.tempView.backgroundColor=[UIColor whiteColor];
    [self.view addSubview:self.tempView];
    UIImageView *imagView=[[UIImageView alloc]initWithFrame:CGRectMake(MainW/2-90, self.tempView.bsg_centerY-0.6*MainW, MainW/2, 0.55*MainW)];
    imagView.image=[UIImage imageNamed:@"img_blank_monk"];
    [self.tempView addSubview:imagView];
    MYLabel* label=[[MYLabel alloc]init];
    label.text=MyString(@"空的");
    label.font=FontAndStyle14;
    CGSize size=[label.text sizeWithAttributes:@{NSFontAttributeName:label.font }];
    label.textColor=TextColor6;
    [self.tempView addSubview:label];
    [label mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(imagView.mas_bottom).offset(15);
        make.centerX.equalTo(self.tempView.mas_centerX);
        make.width.equalTo(size.width);
        make.height.equalTo(20);
    }];
    MYLabel* Zlabel=[[MYLabel alloc]init];
    Zlabel.text=MyString(@"添加商品");
    Zlabel.textColor=TextColor6;
    //Zlabel.font=FontAndStyle14;
    [self.tempView addSubview:Zlabel];
    [Zlabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(label.mas_bottom).offset(15);
        make.left.equalTo(label.mas_left);
        make.right.equalTo(self.tempView.mas_right);
        make.height.equalTo(20);
    }];
    UIButton *btn=[[UIButton alloc]init];
    [btn setTitle:MyString(@"随便逛逛") forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    btn.backgroundColor=HJ_Color(204, 8, 20);
    btn.titleLabel.font=[UIFont systemFontOfSize:15];
    [btn addTarget:self action:@selector(ClickBtn) forControlEvents:UIControlEventTouchUpInside];
    [self.tempView addSubview:btn];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(Zlabel.mas_bottom).offset(20);
        make.centerX.equalTo(self.tempView.mas_centerX);
        make.height.equalTo(50);
        make.width.equalTo(165);
    }];
    ViewRadius(btn, 5);
    
    
}
-(void)ClickBtn{
    MianTabBarViewController *tabbar = [[MianTabBarViewController alloc] init];
    [tabbar setSelectedIndex:0];
    [UIApplication sharedApplication].keyWindow.rootViewController = tabbar;
    NSLog(@"随便逛逛");
}
-(void)loadShopList{
    NSMutableDictionary*dic=[[NSMutableDictionary alloc]init];
    dic[@"userId"]=[ZJUserDefaultsTools getCurrentUserID];
    dic[@"pageNumber"]=@(1);
    dic[@"pageSize"]=@(2);
    [self doHttpRequestWithApi:API_SHOPCARLIST_LIST method:GET dic:dic successBlock:^(NSDictionary *dic) {
        NSArray *arry=dic[@"data"][@"list"];
        if (arry.count==0) {
            self.tempView.hidden=NO;
        }else{
            //dic[@"data"][@"list"]
            self.shopDataArr=[shoppingCarModel mj_objectArrayWithKeyValuesArray:dic[@"data"][@"list"]];
            [self.tableView reloadData];
            [self.tableView.mj_footer endRefreshing];
            //[self createdUI];
        }
        //[self.tableView reloadData];
        //NSLog(@"  二级********%@",self.collectionDatas);
    }];
}
-(void)removeCartShop{
   
   // /api/shopping/cart/remove
    
}
-(void)changShopNumber:(NSString*)sender Number:(int)number  Click:(ShoppingCarTableViewCell *)cell Modle:(shoppingCarModel *)model{

    NSMutableDictionary*dic=[[NSMutableDictionary alloc]init];
    dic[@"userId"]=[ZJUserDefaultsTools getCurrentUserID];
    dic[@"skuId"]=sender;
    dic[@"number"]=[NSString stringWithFormat:@"%ld",(long)number];
    [self doHttpRequestWithApi:API_ShopCarNumber_LIST method:POST dic:dic successBlock:^(NSDictionary *dic) {
            cell.numLabel.text=[NSString stringWithFormat:@"%d",number];
            self.model.quantity= cell.numLabel.text;
        [self calculateThePrice];
    }];

}
-(void)shopNumClick:(UIButton*)sender{
    ShoppingCarTableViewCell*cell=(ShoppingCarTableViewCell *)[[sender superview] superview];
    self.cell=cell;
    CGFloat dilX = 25;
    CGFloat dilH = 150;
    YXCustomAlertView *alertV = [[YXCustomAlertView alloc] initAlertViewWithFrame:CGRectMake(dilX, 0, 280, dilH) andSuperView:self.navigationController.view];
    alertV.countField.text=cell.numLabel.text;
    alertV.center = CGPointMake(MainW/2, MainH/2-30);
    alertV.delegate = self;
    alertV.titleStr = @"输入购买数量";
    self.model=self.shopDataArr[sender.tag];
    

}
#pragma mark - YXCustomAlertViewDelegate
- (void) customAlertView:(YXCustomAlertView *) customAlertView clickedButtonAtIndex:(NSInteger)buttonIndex
{
    [self.view endEditing:YES];
    if (buttonIndex==0) {
        [customAlertView dissMiss];
        customAlertView = nil;
        
        NSLog(@"取消");
        
    }else
    {
        if ([customAlertView.countField.text intValue]<=0) {
            [customAlertView dissMiss];
            customAlertView = nil;
            [self showToast:@"请输入合理数量!"];
            return;
        }
        self.cell.numLabel.text=customAlertView.countField.text;
        [self changShopNumber:self.model.skuId Number:[customAlertView.countField.text intValue] Click:self.cell Modle:self.model];
        
        [customAlertView dissMiss];
        customAlertView = nil;
    }
}
-(void)setupUnreadMessageCount
{
    NSArray *conversations = [[EMClient sharedClient].chatManager getAllConversations];
    NSInteger unreadCount = 0;
    for (EMConversation *conversation in conversations) {
        unreadCount += conversation.unreadMessagesCount;
    }
    NSLog(@"未读消息%ld",(long)unreadCount);
    if (unreadCount>0) {
        NSNotification *notification =[NSNotification notificationWithName:@"unReadInfo" object:nil userInfo:nil];
        // 3.通过 通知中心 发送 通知
        [[NSNotificationCenter defaultCenter] postNotification:notification];
    }else{
        self.itemImage=[UIImage imageNamed:@"icon_message_nor"];
        self.itemImage = [self.itemImage imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
        UIBarButtonItem *rightBarButtonItem=[[UIBarButtonItem alloc]initWithImage:self.itemImage style:UIBarButtonItemStylePlain target:self action:@selector(rightClick)];
        self.navigationItem.rightBarButtonItem =rightBarButtonItem;
    }
    
}

@end
